package com.yww.leetcode2.array;

/**
 * @author yww
 * @description 27. 移除元素
 * @since 2024/10/8
 */
public class RemoveElement27_02 {
    public int removeElement(int[] nums, int val) {
        return remove(nums, val);
    }

    // 快慢指针移除元素
    private static int remove(int[] nums, int val) {
        int fast = 0;
        int slow = 0;

        while (fast < nums.length) {
            if (nums[fast] != val) {
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }
}
